<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>绘制曲线</title>
  </head>
  <body>
    <script>
      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        const quadraticCurveTo = () => {
          ctx.fillStyle = "#00f";
          ctx.beginPath();
          ctx.arc(50, 200, 4, 0, Math.PI * 2);
          ctx.fill();
          ctx.beginPath();
          ctx.arc(100, 100, 4, 0, Math.PI * 2);
          ctx.fill();
          ctx.beginPath();
          ctx.arc(250, 200, 4, 0, Math.PI * 2);
          ctx.fill();

          ctx.beginPath();
          ctx.moveTo(50, 200);
          ctx.quadraticCurveTo(100, 100, 250, 200);
          ctx.stroke();
        };
        // quadraticCurveTo();
        const bezierCurveTo = () => {
          ctx.fillStyle = "#f00";
          ctx.beginPath();
          ctx.arc(50, 200, 4, 0, Math.PI * 2);
          ctx.fill();
          ctx.beginPath();
          ctx.arc(100, 100, 4, 0, Math.PI * 2);
          ctx.fill();
          ctx.beginPath();
          ctx.arc(200, 300, 4, 0, Math.PI * 2);
          ctx.fill();
          ctx.beginPath();
          ctx.arc(250, 200, 4, 0, Math.PI * 2);
          ctx.fill();

          ctx.beginPath();
          ctx.moveTo(50, 200);
          ctx.bezierCurveTo(100, 100, 200, 300, 250, 200);
          ctx.stroke();
        };
        bezierCurveTo();
      })();
    </script>
  </body>
</html>
